#include<iostream>
#include<vector>

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> bills(n);
	for(int i=0;i<n;i++){
		cin>>bills[i];
	}
	
	int five = 0, ten = 0;
    for (auto& bill: bills) {
        if (bill == 5) {
            five++;
        } else if (bill == 10) {
            if (five == 0) {
                cout<<"false";
                return 0;
            }
            five--;
            ten++;
        } else {
            if (five > 0 && ten > 0) {
                five--;
                ten--;
            } else if (five >= 3) {
                five -= 3;
            } else {
            	cout<<"false";
                return 0;
            }
        }
    }
	cout<<"true";
    return 0;
} 
